﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;

namespace WebApmDemo2.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TestController : Controller
    {
        private readonly IHttpClientFactory _httpClient;
        public TestController(IHttpClientFactory httpClient)
        {
            this._httpClient = httpClient;
        }

        [HttpPost, HttpGet]
        public IActionResult Index()
        {
            return Ok("1232131");
        }


        [HttpGet, HttpPost]
        [Route("PostTestA")]
        public async Task<IActionResult> PostTestA()
        {
            var client = new HttpClient();
            //demo2的请求地址
            var url = "http://localhost:5001/api/TestA/TestOne";
            var response = await client.GetAsync(url);
            var result = await response.Content.ReadAsStringAsync();
            return Content(result);
        }



        [HttpGet, HttpPost]
        [Route("TestOne")]
        public IActionResult TestOne()
        {
            Thread.Sleep(5000);
            return Content("我是TestOne");
        }


        [HttpGet, HttpPost]
        [Route("TestTwo")]
        public IActionResult TestTwo()
        {
            throw new Exception("TestTwo报错了 ");
            return Content("我是TestTwo");
        }
    }
}
